//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using OpenLS.Drawing;

namespace OpenLS.Spreadsheet.UI
{
    class TableInfoToForegroundConverter: IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int row = StrictConverter.Convert(values[0], 0);
            int column = StrictConverter.Convert(values[1], 0);
            TableStyle style = StrictConverter.Convert<TableStyle>(values[2]);
            ColorScheme colorScheme = StrictConverter.Convert<ColorScheme>(values[3]);
            TableLayoutInfo i = new TableLayoutInfo(style, new RangeAddress(new CellAddress(0, 0), new CellAddress(4, 4)), true, true,
                1, 1, true, true);
            TableStyleElement element = i.GetElementFor(new CellAddress(row, column), r => r.Font != null && r.Font.Foreground != null);
            if (element == null)
                return null;
            return ColorBrushManager.GetBrush(element.StyleRecord.Font.Foreground, colorScheme);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
